package com.oracle.oa.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.oracle.oa.util.PageBean;
/**
 * 日程分页
 * @author Administrator
 *
 */
public class SchedulePageAction extends ActionSupport implements SessionAware{

	private static final long serialVersionUID = 1L;
	public Map<String, Object> session;
	public String page;//获取当前第几页

	public String url;
	
	@Override
	public String execute() throws Exception {
		
		Long Roleid=(Long) session.get("Roleid");
		
		System.out.println("page的当前页数111="+page);
		
		PageBean pb=new PageBean();
		List pageList=new ArrayList();
		
		int currentPage=1;
		//设置当前页
		
		List slist=(List) session.get("scheList");
		pb.setAllRow(slist.size());  //设置总行数
		
		System.out.println("page的总行数="+slist.size());
		
		if(page!=null){
			currentPage=Integer.parseInt(page);
			if(currentPage<1){
				currentPage=1;
			}
			if(currentPage>pb.getTotalPage()){
				currentPage=pb.getTotalPage();
			}
			
			System.out.println("page的当前页数2222="+page);
			    
		}
		System.out.println("page的当前页数333="+page);
		
		for(int i=0;i<6;i++){
			pageList.add(slist.get((pb.getPageSize()*(currentPage-1))+i));
			if(slist.get((pb.getPageSize()*(currentPage-1))+i).equals(slist.get(slist.size()-1))){
				break;
			}
	    
		}
		
		pb.setList(pageList);
	    pb.setCurrentPage(currentPage);
	    
		session.put("pb", pb); //分页对象
		
		if(1l==Roleid){
			return "cg";
		}
		if(2l==Roleid){
			return "pg";
			
		}else 
	    	return "pt";

	}

	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}


	public String getPage() {
		return page;
	}


	public void setPage(String page) {
		this.page = page;
	}


	public String getUrl() {
		return url;
	}


	public void setUrl(String url) {
		this.url = url;
	}

	
}
